#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

 class Solution {
public:
    vector<string> summaryRanges(vector<int>& nums) {
        vector<string> result;
        if(nums.empty()){
            return result;
        }
        int i = 0;
        int j = 1;
        while(j<nums.size()){
            if(nums[j]==nums[j-1]+1){
                j = j+1;
            }
            else{
                string temp;
                if(i!=j-1){
                    temp = to_string(nums[i])+"->"+to_string(nums[j-1]);
                }
                else{
                    temp = to_string(nums[j-1]);
                }
                result.push_back(temp);
                i = j;
                j=j+1;
            }
        }
        string temp;
        if(i!=j-1){
            temp = to_string(nums[i])+"->"+to_string(nums[j-1]);
        }
        else{
            temp = to_string(nums[j-1]);
        }
        result.push_back(temp);
        return result;
    }
};

int main(){
    Solution S;
    vector<int> nums = {0,2,3,4,6,8,9};
    vector<string> result = S.summaryRanges(nums);
    return 0;
}